import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import store from './store'
import routes from './router'
import ElementUi from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
import './public-path'
Vue.config.productionTip = false

Vue.use(VueRouter)
Vue.use(ElementUi)
// new Vue({
//   render: h => h(App),
// }).$mount('#app')

let router = null;
let instance = null;

//single-spa的生命周期函数
export async function bootstrap({ fns = [] } = {}) {
  Array.isArray(fns) && fns.map(i => {
    Vue.prototype[i.name] = i
  });
}

export async function mount({ data = {} } = {}) {
  console.log(data)
  store.commit('FROM_DATA',data.msg)
  router = new VueRouter({
    base: window.__POWERED_BY_QIANKUN__ ? "/layout/app4" : "/",
    mode: "history",
    routes
  });
  instance = new Vue({
    router,
    store,
    render: h => h(App, { props: {data} })
  }).$mount("#app4");
}

export async function unmount() {
  instance.$destroy();
  instance = null;
  router = null;
}

console.log(window.__POWERED_BY_QIANKUN__)
// 单独开发环境
window.__POWERED_BY_QIANKUN__ || mount();